package com.shiguo365.market.application;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.util.Log;
import android.widget.Toast;

import com.liulishuo.filedownloader.FileDownloader;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.shiguo365.market.utils.MyDatabaseHelper;


import biz.yfsoft.api.ae.AE;
import cn.jpush.android.api.JPushInterface;
import im.fir.sdk.FIR;
import im.fir.sdk.VersionCheckCallback;

/**
 * Created by caomenglong on 16/7/6.
 */
public class MyApplication extends Application {
    private static MyApplication mcontext;
    public final static String FIRAPITOKEN="9a27347dce1d121d00f8cd13b4f80c14";  //FIR API TOKEN
    private static MyDatabaseHelper myDatabaseHelper;
    @Override
    public void onCreate() {
        super.onCreate();
        mcontext=this;
        //图片缓存控件初始化
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
                .build();
        ImageLoader.getInstance().init(config);

        //本地环境
        //AE.me().init("08d7b0fa132b2880","6026a8e2264e94f8b8dcb57a7b428d6d").setMode(AE.MODE_DEV);

        //测试环境
        AE.me().init("609388a15b3dfaca","1292b2d414d45c8f97d44354de24c40c").setMode(AE.MODE_STAGING);


        FIR.init(this); //性能监控

        FileDownloader.init(this); //下载工具初始化

        JPushInterface.setDebugMode(true);
        JPushInterface.init(this);

        myDatabaseHelper=new MyDatabaseHelper(this,MyDatabaseHelper.name+".db",null,MyDatabaseHelper.version);
        myDatabaseHelper.getWritableDatabase();


    }


    public static Context getAppContext(){
        return mcontext;
    }
    public static Resources getAppResources(){
        return getAppResources();
    }


    //获取用户的UID
    public static Integer getUID(){
        SharedPreferences preferences=getAppContext().getSharedPreferences("data", Context.MODE_PRIVATE);
        Integer UID=preferences.getInt("uid",1);
        return UID;
    }

    //获取数据库句柄
    public static MyDatabaseHelper getDbHelper(){
        return myDatabaseHelper;
    }


}
